<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"><meta name="referrer" content="no-referrer" />
    <title>pyq页面</title>
    <script src="js/jquery-1.11.0.min.js"></script>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/materialdesignicons.min.css" rel="stylesheet">
    <link href="css/style.min.css" rel="stylesheet">
    <style>
        .left-side {
            position: fixed;
            top: 0;
            bottom: 0;
            z-index: 5;
            display: block;
            width: 240px;
            font-weight: 500;
        }
        .submenu >ul{
            display: none;
        }
        .open>ul{
            display: block;
        }
    </style>
    <script>
        $(function () {
            console.log("进入头部");
            $(".header").load("headHtml");
            console.log("展示公告！");
            $.post("/getUserName", function (obj) {
                $.ajax({
                    url: "/getPyqs",
                    type: "POST",
                    success: function (result) {
                        console.log("---------");
                        console.log(result);
                        console.log("---------");
                        if (result != null) {
                            console.log("查到了pyq");
                            $imgs = $(".card");
                            var li = '';
                            for (let i = 0; i < result.length; i++) {
                                var info = JSON.stringify(result[i]);
                                li = li + '<div id="contentCon" style="margin: 0 auto;height: fit-content">\n' +
                                    '                                <p id="title" style="font-size: 30px"> <<<<' + result[i].title + '>>>> </p>\n' +
                                    '                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="' + result[i].url + '" style="height: 140px;width: 210px">\n' +
                                    '                                <p id="content">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + result[i].con + '</p>' +
                                    '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button onclick="add(' + info.replace(/"/g, '&quot;') + ')">添加收藏</button>' +
                                    '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;点赞量' + result[i].zan + '' +
                                    '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button onclick="dianzan(' + result[i].id + ')">点赞</button>\n' +
                                    '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button onclick="cai(' + result[i].id + ')">踩</button>\n' +
                                    '                                <p id="date" style="float: right">来自用户' + result[i].username + '的分享&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + result[i].date + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p></br>\n' +
                                    '                            </div>';

                            }
                            $imgs.html(li);
                        }
                    }
                });
            }, "json");
        });
        function dianzan(id){
            $.post("/getUserName", function (obj) {
                console.log("用户数据为：" + obj);
                if (obj!=100&&obj!=null) {
                    $.ajax({
                        url: "dianzan",
                        type: "POST",
                        contentType: "application/json",//划重点
                        // async:false,//同步，默认异步
                        dataType: "json",
                        data: JSON.stringify({"id": id}),//划重点
                        success: function (data) {
                            if (data===1){
                                window.location.href = "share";
                            }
                        }
                    });
                } else {
                    if (confirm("您还未登录，是否先登录？")) {
                        console.log("您选择了是");
                        window.location.href = "loginHtml";
                    } else {
                        console.log("您选择了否");
                        window.location.href = "share";
                    }
                }
            });
        }
        function cai(id){
            $.post("/getUserName", function (obj) {
                console.log("用户数据为：" + obj);
                if (obj!=100&&obj!=null) {
                    $.ajax({
                        url: "cai",
                        type: "POST",
                        contentType: "application/json",//划重点
                        // async:false,//同步，默认异步
                        dataType: "json",
                        data: JSON.stringify({"id": id}),//划重点
                        success: function (data) {
                            if (data===1){
                                window.location.href = "share";
                            }
                        }
                    });
                } else {
                    if (confirm("您还未登录，是否先登录？")) {
                        console.log("您选择了是");
                        window.location.href = "loginHtml";
                    } else {
                        console.log("您选择了否");
                        window.location.href = "share";
                    }
                }
            });
        }
        function add(a){
            $.post("/getUserName", function (obj) {
                console.log("用户数据为：" + obj);
                if (obj!=null&&obj!=100) {
                    console.log("执行添加方法");
                    $.ajax({
                        url: "addPyqToPicture",
                        type: "POST",
                        contentType: "application/json",//划重点
                        // async:false,//同步，默认异步
                        dataType: "json",
                        data: JSON.stringify({"pyq": a}),//划重点
                        success: function (data) {
                            if (data===1){
                                confirm("添加收藏成功！");
                                window.location.href = "displayHtml";
                            }
                        }
                    });
                } else {
                    if (confirm("您还未登录，是否先登录？")) {
                        console.log("您选择了是");
                        window.location.href = "loginHtml";
                    } else {
                        console.log("您选择了否");
                        window.location.href = "share";
                    }
                }
            });
        }
        function moren(){
            $.ajax({
                url: "/getPyqs",
                type: "POST",
                success: function (result) {
                    console.log("---------");
                    console.log(result);
                    console.log("---------");
                    if (result != null) {
                        console.log("查到了pyq");
                        $imgs = $(".card");
                        var li = '';
                        for (let i = 0; i < result.length; i++) {
                            var info = JSON.stringify(result[i]);
                            li = li + '<div id="contentCon" style="margin: 0 auto;height: fit-content">\n' +
                                '                                <p id="title" style="font-size: 30px"> <<<<' + result[i].title + '>>>> </p>\n' +
                                '                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="' + result[i].url + '" style="height: 140px;width: 210px">\n' +
                                '                                <p id="content">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + result[i].con + '</p>' +
                                '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button onclick="add(' + info.replace(/"/g, '&quot;') + ')">添加收藏</button>' +
                                '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;点赞量' + result[i].zan + '' +
                                '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button onclick="dianzan(' + result[i].id + ')">点赞</button>\n' +
                                '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button onclick="cai(' + result[i].id + ')">踩</button>\n' +
                                '                                <p id="date" style="float: right">' + result[i].date + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p></br>\n' +
                                '                            </div>';

                        }
                        $imgs.html(li);
                    }
                }
            });
        }
        function dianzanliang(){
            $.ajax({
                url: "/getPyqsOrderByZan",
                type: "POST",
                success: function (result) {
                    console.log("---------");
                    console.log(result);
                    console.log("---------");
                    if (result != null) {
                        console.log("查到了pyq");
                        $imgs = $(".card");
                        var li = '';
                        for (let i = 0; i < result.length; i++) {
                            var info = JSON.stringify(result[i]);
                            li = li + '<div id="contentCon" style="margin: 0 auto;height: fit-content">\n' +
                                '                                <p id="title" style="font-size: 30px"> <<<<' + result[i].title + '>>>> </p>\n' +
                                '                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="' + result[i].url + '" style="height: 140px;width: 210px">\n' +
                                '                                <p id="content">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + result[i].con + '</p>' +
                                '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button onclick="add(' + info.replace(/"/g, '&quot;') + ')">添加收藏</button>' +
                                '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;点赞量' + result[i].zan + '' +
                                '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button onclick="dianzan(' + result[i].id + ')">点赞</button>\n' +
                                '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button onclick="cai(' + result[i].id + ')">踩</button>\n' +
                                '                                <p id="date" style="float: right">' + result[i].date + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p></br>\n' +
                                '                            </div>';

                        }
                        $imgs.html(li);
                    }
                }
            });
        }
    </script>
    <script>
        $(function () {
            $('.submenu').mouseover(function(){
                $(this).addClass('open');
            }).mouseout(function(){
                $(this).removeClass('open');
            });
        })
    </script>
</head>
<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        <aside class="lyear-layout-sidebar">
            <!-- logo -->
            <div id="logo" class="sidebar-header">
                <h1 style="text-align: center;color: #33cabb;">Spider</h1>
            </div>
            <div class="lyear-layout-sidebar-scroll">
                <nav class="sidebar-main">
                    <ul class="nav nav-drawer" style="list-style: none">
                        <li class="nav-item active"><a href="/notice"><i class="mdi mdi-home"></i>公告栏</a></li>
                        <li class="nav-item active"><a href="/index"><i class="mdi mdi-home"></i>爬取图片</a></li>
                        <li class="nav-item active"><a href="/displayHtml"><i class="mdi mdi-home"></i>我的收藏</a></li>
                        <li class="nav-item active"><a href="/share"><i class="mdi mdi-home"></i>好图分享</a></li>
                        <li class="nav-item active submenu"><a href="#"><i class="mdi mdi-home"></i>个人中心</a>
                            <ul class="nav nav-drawer">
                                <li class="nav-item active"><a href="/self">&nbsp&nbsp&nbsp&nbsp<i class="mdi mdi-step-forward"></i>信息编辑</a></li>
                                <li class="nav-item active"><a href="/record">&nbsp&nbsp&nbsp&nbsp<i class="mdi mdi-step-forward"></i>爬取记录</a></li>
                                <li class="nav-item active"><a href="/comment">&nbsp&nbsp&nbsp&nbsp<i class="mdi mdi-step-forward"></i>评论反馈</a></li>
                            </ul>
                        </li>
                    </ul>
                </nav>
            </div>
        </aside>
        <!--End 左侧导航-->
        <!--头部信息-->
        <div class="header"></div>
        <!--End 头部信息-->
        <!-- 主题内容 -->
        <!--页面主要内容 table table-striped table-hover-->
        <main class="lyear-layout-content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        <button onclick="moren()">默认排序</button><button onclick="dianzanliang()">按点赞量排序</button>
                        <div class="card">

                        </div>
                    </div>
                </div>
            </div>
        </main>
        <!--End 页面主要内容-->
    </div>
</div>
</body>
</html>